package com.zrrd.stackandqueue;

import java.util.Arrays;
import java.util.Stack;

public class BinaryExchange {

    public int[] binaryExchange(int num) {
        Stack<Integer> stack = new Stack();
        if (num % 2 != 0) {
            stack.push(1);
            num = (num - 1) / 2;
        } else {
            stack.push(0);
            num = num / 2;
        }
        while (num > 0) {
            stack.push(num % 2);
            num = num / 2;
        }
        int[] array = new int[stack.size()];
        int i = 0;
        while (!stack.isEmpty()) {
            array[i] = stack.pop();
            i++;
        }
        return array;
    }

    public static void main(String[] args) {
        BinaryExchange binaryExchange = new BinaryExchange();
        System.out.println(Arrays.toString(binaryExchange.binaryExchange(36)));
    }
}
